package org.ne.banksys.mapper;

import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.*;
import org.ne.banksys.entity.User;

import java.util.List;

/**
 * @author wey
 * @date 2025/6/13 下午10:39 06
 **/

@Mapper
public interface UserMapper {

    @Select("select * from user")
    List<User> getAll();

    @Select("select * from user where customer_name=#{username}")
    User findByUserName(String username);

    @Select("select * from user where PID=#{pid}")
    User findByUserPID(String pid);

    @Select("select * from user where telephone=#{phone}")
    User findByUserPhone(String phone);

    @Select("select * from user where customer_id=#{customerId}")
    User findByCustomerId(Long customerId);


    @Insert("insert into user(customer_name,PID, telephone, password)" + "values (#{username}, #{pid}, #{phone}, #{password})")
//    void add(@Param("username") String username, @Param("password")  String password);
    void add(@Param("username") String username,@Param("password")  String password,@Param("pid")  String pid, @Param("phone") String phone);



    @Update("update user set customer_name=#{customerName}, PID=#{PID}, telephone=#{telephone} where customer_id=#{customerId}")
    void update(User user);


    @Update("update user set address=#{address} where customer_id=#{id}")
    void updateAddress(@Param("address") String address, @Param("id") Long id);


    @Update("update user set password=#{password}  where customer_id=#{id}")
    void updatePwd(@Param("password") String password, @Param("id") Long id);

    @Delete(("delete from user where PID=#{pid} and customer_name=#{username} and password=#{pass}"))
    void delete(String pid, String username, String pass);


    @Delete("delete from user where customer_id=#{id}")
    void deleteById(Long id);

    @Select("select * from user limit #{pageNum}, #{pageSize}")
    Page<User> getPage(@Param("pageNum") Integer pageNum, @Param("pageSize") Integer pageSize);





    @Select("SELECT * FROM user u WHERE u.customer_name LIKE CONCAT('%', #{keyword}, '%')")
    List<User> searchByCustomerName(@Param("keyword") String keyword);
}
